package com.hnyfkj.jyindustry.biz.raspi.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hnyfkj.jyindustry.biz.raspi.dao.RaspiDao;
import com.hnyfkj.jyindustry.biz.raspi.dto.RaspiInsertDto;
import com.hnyfkj.jyindustry.biz.raspi.dto.RaspiQueryDto;
import com.hnyfkj.jyindustry.biz.raspi.dto.RaspiUpdateDto;
import com.hnyfkj.jyindustry.biz.raspi.entity.Raspi;
import com.hnyfkj.jyindustry.biz.raspi.service.RaspiService;
import com.hnyfkj.jyindustry.biz.raspi.vo.RaspiVo;
import com.hnyfkj.jyindustry.common.dto.PageReturnDto;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;

@Service("raspiService")
public class RaspiServiceImpl extends ServiceImpl<RaspiDao, Raspi> implements RaspiService {


    @Autowired
    private RaspiDao raspiDao;

    @Override
    public PageReturnDto<RaspiVo> queryPage(RaspiQueryDto queryDto) {
        PageInfo<RaspiVo> page =
                PageHelper.startPage(queryDto.getPage(), queryDto.getLimit()).doSelectPageInfo(() -> raspiDao.selectListByQuery(queryDto));
        return PageReturnDto.pageOf(page);
    }

    @Override
    public int insert(RaspiInsertDto RaspiInsertDto) {
        final Raspi piScreen = new Raspi();
        BeanUtils.copyProperties(RaspiInsertDto, piScreen);
        return raspiDao.insert(piScreen);
    }

    @Override
    public int update(RaspiUpdateDto RaspiUpdateDto) {
        final Raspi piScreen = new Raspi();
        BeanUtils.copyProperties(RaspiUpdateDto, piScreen);
        return raspiDao.updateById(piScreen);
    }

    @Override
    public int delete(String ids) {
        String[] id = ids.split(",");
        return raspiDao.deleteBatchIds(Arrays.asList(id));
    }
}